package com.gjy.elasticjob.job;

import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.dataflow.job.DataflowJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-08-28 09:38:43
 */
public class ShardProcessJob implements DataflowJob<String> {
    private static final Logger log = LoggerFactory.getLogger(ShardProcessJob.class);

    @Override
    public List<String> fetchData(ShardingContext shardingContext) {
        int item = shardingContext.getShardingItem();
        switch (item) {
            case 0:
                List<String> list = new ArrayList<>();
                list.add("Hello 0");
                return list;
            case 1:
                List<String> list1 = new ArrayList<>();
                list1.add("Hello 1");
                return list1;
            case 2:
                List<String> list2 = new ArrayList<>();
                list2.add("Hello 2");
                return list2;
            default:
                List<String> list3 = new ArrayList<>();
                list3.add("Hello 3");
                return list3;
        }
    }

    @Override
    public void processData(ShardingContext shardingContext, List<String> list) {
        log.info("shard: {}   {}", shardingContext.getShardingItem(), list);
    }

}
